# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=iputils
pkgver=20240905
pkgrel=0
pkgdesc="IP Configuration Utilities"
url="https://github.com/iputils/iputils/"
arch="all"
license="BSD-3-Clause AND GPL-2.0-or-later"
replaces="bbsuid"
makedepends="
	libcap-dev
	meson
	"
subpackages="
	iputils-arping
	iputils-clockdiff
	iputils-ping
	iputils-tracepath
	"
source="iputils-$pkgver.tar.xz::https://github.com/iputils/iputils/releases/download/$pkgver/iputils-$pkgver.tar.xz"
# checks need suid/setcap'd binaries
# ping is suid
options="suid !check"

build() {
	abuild-meson \
		-Db_lto=true \
		-DNO_SETCAP_OR_SUID=true \
		-DBUILD_MANS=false \
		-DUSE_IDN=false \
		-DUSE_GETTEXT=false \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	depends="
		iputils-arping=$pkgver-r$pkgrel
		iputils-clockdiff=$pkgver-r$pkgrel
		iputils-ping=$pkgver-r$pkgrel
		iputils-tracepath=$pkgver-r$pkgrel
		"

	install -Dm4755 output/ping/ping "$pkgdir"/bin/ping

	for name in arping clockdiff tracepath; do
		install -Dm755 output/$name "$pkgdir"/usr/sbin/$name
	done

	ln -s tracepath "$pkgdir"/usr/sbin/tracepath6
	ln -s ping "$pkgdir"/bin/ping6
}

arping() {
	pkgdesc="$pkgdesc (arping utility)"
	amove usr/sbin/arping
}

clockdiff() {
	pkgdesc="$pkgdesc (clockdiff utility)"
	amove usr/sbin/clockdiff
}

ping() {
	pkgdesc="$pkgdesc (ping utility)"
	amove bin/ping*
}

tracepath() {
	pkgdesc="$pkgdesc (tracepath utility)"
	amove usr/sbin/tracepath*
}

sha512sums="
6731e4fb8b8f89469de746c911fca6f1c7e924a21ca14ec25c40707707be3fe5a696272ba2d293207bc8c20f72a070d8e0a640fab9e5ea240a29a1f027807c1b  iputils-20240905.tar.xz
"
